<template>
  <button 
    class="pink-button" 
    :class="[
      `pink-button--${type}`,
      `pink-button--${size}`,
      {
        'pink-button--plain': plain,
        'pink-button--round': round,
        'pink-button--block': block,
        'pink-button--disabled': disabled,
        'pink-button--loading': loading
      }
    ]"
    :disabled="disabled || loading"
    @click="handleClick"
  >
    <view v-if="loading" class="pink-button__loading">
      <view class="loading-spinner"></view>
    </view>
    <view v-if="icon && !loading" class="pink-button__icon">
      {{ icon }}
    </view>
    <view v-if="$slots.default" class="pink-button__text">
      <slot></slot>
    </view>
  </button>
</template>

<script lang="ts" setup>
interface Props {
  type?: 'primary' | 'default' | 'success' | 'warning' | 'danger'
  size?: 'small' | 'medium' | 'large'
  plain?: boolean
  round?: boolean
  block?: boolean
  disabled?: boolean
  loading?: boolean
  icon?: string
}

const props = withDefaults(defineProps<Props>(), {
  type: 'primary',
  size: 'medium',
  plain: false,
  round: false,
  block: false,
  disabled: false,
  loading: false
})

const emit = defineEmits<{
  click: [event: Event]
}>()

function handleClick(event: Event) {
  if (props.disabled || props.loading) return
  emit('click', event)
}
</script>

<style lang="scss" scoped>
.pink-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  
  &:active {
    transform: scale(0.95);
  }
  
  &__loading {
    margin-right: 8px;
  }
  
  &__icon {
    margin-right: 8px;
    font-size: 16px;
  }
  
  &__text {
    flex: 1;
  }
  
  // 尺寸
  &--small {
    padding: 6px 16px;
    font-size: 12px;
    border-radius: 16px;
    
    .pink-button__icon {
      font-size: 14px;
      margin-right: 4px;
    }
  }
  
  &--medium {
    padding: 10px 20px;
    font-size: 14px;
  }
  
  &--large {
    padding: 14px 28px;
    font-size: 16px;
    border-radius: 24px;
  }
  
  // 类型
  &--primary {
    background: linear-gradient(135deg, #ff69b4, #ff1493);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 105, 180, 0.3);
    
    &:hover, &:focus {
      background: linear-gradient(135deg, #ff1493, #dc143c);
      box-shadow: 0 6px 16px rgba(255, 105, 180, 0.4);
      transform: translateY(-1px);
    }
    
    &.pink-button--plain {
      background: transparent;
      color: #ff69b4;
      border: 2px solid #ff69b4;
      box-shadow: none;
      
      &:hover, &:focus {
        background: rgba(255, 105, 180, 0.1);
        color: #ff1493;
        border-color: #ff1493;
      }
    }
  }
  
  &--default {
    background: rgba(255, 255, 255, 0.9);
    color: #ff69b4;
    border: 2px solid #ff69b4;
    box-shadow: 0 2px 8px rgba(255, 105, 180, 0.2);
    
    &:hover, &:focus {
      background: rgba(255, 105, 180, 0.1);
      color: #ff1493;
      border-color: #ff1493;
    }
  }
  
  &--success {
    background: linear-gradient(135deg, #ff91a4, #ff69b4);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 145, 164, 0.3);
    
    &:hover, &:focus {
      background: linear-gradient(135deg, #ff69b4, #ff1493);
    }
  }
  
  &--warning {
    background: linear-gradient(135deg, #ffb6c1, #ff91a4);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 182, 193, 0.3);
    
    &:hover, &:focus {
      background: linear-gradient(135deg, #ff91a4, #ff69b4);
    }
  }
  
  &--danger {
    background: linear-gradient(135deg, #ff1493, #dc143c);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 20, 147, 0.3);
    
    &:hover, &:focus {
      background: linear-gradient(135deg, #dc143c, #b22222);
    }
  }
  
  // 形状
  &--round {
    border-radius: 50px;
  }
  
  &--block {
    width: 100%;
    display: flex;
  }
  
  // 状态
  &--disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    
    &:hover, &:focus {
      transform: none !important;
      box-shadow: none !important;
    }
  }
  
  &--loading {
    cursor: not-allowed;
    
    .pink-button__text {
      opacity: 0.6;
    }
  }
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>
